forum

Home / DeveloperSection / Forums / How to create AlertDialog in android?

How to create AlertDialog in android?

Anonymous User 1913 16-Oct-2014
Iam Showing a AlertDialog on Device Shake. The issue is that when I shake the device the AlertDialog shows twice. Hence, if I dismiss the AlertDialog, the top one gets dismissed but there is one still showing after that behind the first one.

Also, Iam showing the same AlertDialog from another section of code where it is shown on a button click which works fine.

All of this is done within a ViewPager.

How can I avoid this scenario?

Here is my code:-

@Override
public void onShake(float force) 
{
    // TODO Auto-generated method stub
    showDialog(timeString, "Confirm .");
}
public void showDialog(String timeString, String title)
    {
        builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(title);
        builder.setMessage("Reaching at:"+" "+ timeString+"?");
        builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Do nothing
            }
        });
        builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) 
            {
                // Do nothing but close the dialog
                new AddStatusTask().execute();
            }

Updated on 16-Oct-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By